#include "clueCardPlayStatusMessage.h"
#include "jsonUtils.h"

ClueCardPlayStatusMessage::ClueCardPlayStatusMessage(MtpProtocol* packet) : MtpMessage(packet),param(0,0),duration(0),position(0),volume(0)
{

}

ClueCardPlayStatusMessage::ClueCardPlayStatusMessage(const int64_t& clueCardId, const int& channel, const int& duration, const int& position, const int& volume) 
	: MtpMessage(new MtpProtocol(L"clueCardPlayStatus")),param(clueCardId,channel),duration(duration),position(position),volume(volume)
{

}

void ClueCardPlayStatusMessage::decodeBody()
{
	MtpMessage::decodeBody();
	JsonDoc& doc = param.jsonDeserialize(jsonContent);
	JsonUtils::loadInt(doc, L"duration", duration);
	JsonUtils::loadInt(doc, L"position", position);
	JsonUtils::loadInt(doc, L"volume", volume);
}

void ClueCardPlayStatusMessage::encodeBody()
{
	JsonDoc& doc = param.jsonSerialize();
	doc.AddMember(L"duration", duration, doc.GetAllocator());
	doc.AddMember(L"position", position, doc.GetAllocator());
	doc.AddMember(L"volume", volume, doc.GetAllocator());
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}
